{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号\n",
    "pd.set_option('max_columns', 100)  #最大展示特征列数量\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\main\\local\\Anaconda3\\envs\\tf1.14\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3063: DtypeWarning: Columns (12,18) have mixed types.Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>DOB</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>Female</td>\n",
       "      <td>Delhi</td>\n",
       "      <td>20000</td>\n",
       "      <td>23-May-78</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>CYBOSOL</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>N</td>\n",
       "      <td>0</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>G</td>\n",
       "      <td>S122</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Mumbai</td>\n",
       "      <td>35000</td>\n",
       "      <td>07-Oct-85</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TATA CONSULTANCY SERVICES LTD (TCS)</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>13</td>\n",
       "      <td>HBXA</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>G</td>\n",
       "      <td>S122</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>Male</td>\n",
       "      <td>Panchkula</td>\n",
       "      <td>22500</td>\n",
       "      <td>10-Oct-81</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ALCHEMIST HOSPITALS LTD</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S143</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>Male</td>\n",
       "      <td>Saharsa</td>\n",
       "      <td>35000</td>\n",
       "      <td>30-Nov-87</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>BIHAR GOVERNMENT</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>Y</td>\n",
       "      <td>10</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S143</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Bengaluru</td>\n",
       "      <td>100000</td>\n",
       "      <td>17-Feb-84</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>GLOBAL EDGE SOFTWARE</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>17</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S134</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender       City  Monthly_Income        DOB  \\\n",
       "0  ID000002C20  Female      Delhi           20000  23-May-78   \n",
       "1  ID000004E40    Male     Mumbai           35000  07-Oct-85   \n",
       "2  ID000007H20    Male  Panchkula           22500  10-Oct-81   \n",
       "3  ID000008I30    Male    Saharsa           35000  30-Nov-87   \n",
       "4  ID000009J40    Male  Bengaluru          100000  17-Feb-84   \n",
       "\n",
       "  Lead_Creation_Date  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "0          15-May-15             300000.0                  5.0           0.0   \n",
       "1          04-May-15             200000.0                  2.0           0.0   \n",
       "2          19-May-15             600000.0                  4.0           0.0   \n",
       "3          09-May-15            1000000.0                  5.0           0.0   \n",
       "4          20-May-15             500000.0                  2.0       25000.0   \n",
       "\n",
       "                         Employer_Name       Salary_Account Mobile_Verified  \\\n",
       "0                              CYBOSOL            HDFC Bank               N   \n",
       "1  TATA CONSULTANCY SERVICES LTD (TCS)           ICICI Bank               Y   \n",
       "2              ALCHEMIST HOSPITALS LTD  State Bank of India               Y   \n",
       "3                     BIHAR GOVERNMENT  State Bank of India               Y   \n",
       "4                 GLOBAL EDGE SOFTWARE            HDFC Bank               Y   \n",
       "\n",
       "  Var5  Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0    0  HBXX                    NaN                    NaN            NaN   \n",
       "1   13  HBXA               200000.0                    2.0          13.25   \n",
       "2    0  HBXX               450000.0                    4.0            NaN   \n",
       "3   10  HBXX               920000.0                    5.0            NaN   \n",
       "4   17  HBXX               500000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee EMI_Loan_Submitted Filled_Form  Device_Type Var2 Source  \\\n",
       "0             NaN                NaN           N  Web-browser    G   S122   \n",
       "1             NaN             6762.9           N  Web-browser    G   S122   \n",
       "2             NaN                NaN           N  Web-browser    B   S143   \n",
       "3             NaN                NaN           N  Web-browser    B   S143   \n",
       "4             NaN                NaN           N  Web-browser    B   S134   \n",
       "\n",
       "   Var4  LoggedIn  Disbursed  \n",
       "0     1         0        0.0  \n",
       "1     3         0        0.0  \n",
       "2     1         0        0.0  \n",
       "3     3         0        0.0  \n",
       "4     3         1        0.0  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取数据\n",
    "# path to where the data lies\n",
    "dpath = './data/'\n",
    "train = pd.read_csv(dpath +\"Train1.csv\", encoding='utf-8')\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>8.702000e+04</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>86949.000000</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>5.240700e+04</td>\n",
       "      <td>52407.000000</td>\n",
       "      <td>27726.000000</td>\n",
       "      <td>27420.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87019.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>5.884997e+04</td>\n",
       "      <td>2.302507e+05</td>\n",
       "      <td>2.131399</td>\n",
       "      <td>3.696228e+03</td>\n",
       "      <td>3.950106e+05</td>\n",
       "      <td>3.891369</td>\n",
       "      <td>19.197474</td>\n",
       "      <td>5131.150839</td>\n",
       "      <td>2.949793</td>\n",
       "      <td>0.029350</td>\n",
       "      <td>0.014629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.177511e+06</td>\n",
       "      <td>3.542068e+05</td>\n",
       "      <td>2.014193</td>\n",
       "      <td>3.981021e+04</td>\n",
       "      <td>3.082481e+05</td>\n",
       "      <td>1.165359</td>\n",
       "      <td>5.834213</td>\n",
       "      <td>4725.837644</td>\n",
       "      <td>1.697736</td>\n",
       "      <td>0.168785</td>\n",
       "      <td>0.120063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>5.000000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.990000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.000000e+05</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.250000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>4000.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3.500000e+03</td>\n",
       "      <td>5.000000e+05</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>6250.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>4.445544e+08</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>3.000000e+06</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "count    8.702000e+04         8.694900e+04         86949.000000  8.694900e+04   \n",
       "mean     5.884997e+04         2.302507e+05             2.131399  3.696228e+03   \n",
       "std      2.177511e+06         3.542068e+05             2.014193  3.981021e+04   \n",
       "min      0.000000e+00         0.000000e+00             0.000000  0.000000e+00   \n",
       "25%      1.650000e+04         0.000000e+00             0.000000  0.000000e+00   \n",
       "50%      2.500000e+04         1.000000e+05             2.000000  0.000000e+00   \n",
       "75%      4.000000e+04         3.000000e+05             4.000000  3.500000e+03   \n",
       "max      4.445544e+08         1.000000e+07            10.000000  1.000000e+07   \n",
       "\n",
       "       Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "count           5.240700e+04           52407.000000   27726.000000   \n",
       "mean            3.950106e+05               3.891369      19.197474   \n",
       "std             3.082481e+05               1.165359       5.834213   \n",
       "min             5.000000e+04               1.000000      11.990000   \n",
       "25%             2.000000e+05               3.000000      15.250000   \n",
       "50%             3.000000e+05               4.000000      18.000000   \n",
       "75%             5.000000e+05               5.000000      20.000000   \n",
       "max             3.000000e+06               6.000000      37.000000   \n",
       "\n",
       "       Processing_Fee          Var4      LoggedIn     Disbursed  \n",
       "count    27420.000000  87020.000000  87020.000000  87019.000000  \n",
       "mean      5131.150839      2.949793      0.029350      0.014629  \n",
       "std       4725.837644      1.697736      0.168785      0.120063  \n",
       "min        200.000000      0.000000      0.000000      0.000000  \n",
       "25%       2000.000000      1.000000      0.000000      0.000000  \n",
       "50%       4000.000000      3.000000      0.000000      0.000000  \n",
       "75%       6250.000000      5.000000      0.000000      0.000000  \n",
       "max      50000.000000      7.000000      1.000000      1.000000  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 87020 entries, 0 to 87019\n",
      "Data columns (total 26 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   ID                     87020 non-null  object \n",
      " 1   Gender                 87020 non-null  object \n",
      " 2   City                   86017 non-null  object \n",
      " 3   Monthly_Income         87020 non-null  int64  \n",
      " 4   DOB                    87020 non-null  object \n",
      " 5   Lead_Creation_Date     87020 non-null  object \n",
      " 6   Loan_Amount_Applied    86949 non-null  float64\n",
      " 7   Loan_Tenure_Applied    86949 non-null  float64\n",
      " 8   Existing_EMI           86949 non-null  float64\n",
      " 9   Employer_Name          86949 non-null  object \n",
      " 10  Salary_Account         75256 non-null  object \n",
      " 11  Mobile_Verified        87020 non-null  object \n",
      " 12  Var5                   87020 non-null  object \n",
      " 13  Var1                   87019 non-null  object \n",
      " 14  Loan_Amount_Submitted  52407 non-null  float64\n",
      " 15  Loan_Tenure_Submitted  52407 non-null  float64\n",
      " 16  Interest_Rate          27726 non-null  float64\n",
      " 17  Processing_Fee         27420 non-null  float64\n",
      " 18  EMI_Loan_Submitted     27727 non-null  object \n",
      " 19  Filled_Form            87020 non-null  object \n",
      " 20  Device_Type            87020 non-null  object \n",
      " 21  Var2                   87020 non-null  object \n",
      " 22  Source                 87020 non-null  object \n",
      " 23  Var4                   87020 non-null  int64  \n",
      " 24  LoggedIn               87020 non-null  int64  \n",
      " 25  Disbursed              87019 non-null  float64\n",
      "dtypes: float64(8), int64(3), object(15)\n",
      "memory usage: 17.3+ MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ID', 'Gender', 'City', 'Monthly_Income', 'DOB', 'Lead_Creation_Date',\n",
       "       'Loan_Amount_Applied', 'Loan_Tenure_Applied', 'Existing_EMI',\n",
       "       'Employer_Name', 'Salary_Account', 'Mobile_Verified', 'Var5', 'Var1',\n",
       "       'Loan_Amount_Submitted', 'Loan_Tenure_Submitted', 'Interest_Rate',\n",
       "       'Processing_Fee', 'EMI_Loan_Submitted', 'Filled_Form', 'Device_Type',\n",
       "       'Var2', 'Source', 'Var4', 'LoggedIn', 'Disbursed'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#feature_name = \"Gender\"\n",
    "#train[feature_name], uniques  = pd.factorize(train[feature_name])\n",
    "#train[feature_name] = train[feature_name].astype(np.uint16)\n",
    "#print(uniques)\n",
    "#train.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gender\n",
      "Index(['Female', 'Male'], dtype='object')\n",
      "City\n",
      "Index(['Delhi', 'Mumbai', 'Panchkula', 'Saharsa', 'Bengaluru', 'Sindhudurg',\n",
      "       'Kochi', 'Surat', 'Pune', 'Bhubaneswar',\n",
      "       ...\n",
      "       'RADHANPUR', 'Doda', 'Narayanpur', 'KAPADWANJ', 'Baksa', 'Tamenglong',\n",
      "       'DHORAJI', 'Siruguppa', 'Lakshadweep', 'Lohit'],\n",
      "      dtype='object', length=697)\n",
      "Salary_Account\n",
      "Index(['HDFC Bank', 'ICICI Bank', 'State Bank of India', 'HSBC', 'Yes Bank',\n",
      "       'Kotak Bank', 'Indian Overseas Bank', 'Bank of Maharasthra',\n",
      "       'Axis Bank', 'Central Bank of India', 'Standard Chartered Bank',\n",
      "       'Andhra Bank', 'Bank of India', 'IndusInd Bank', 'Corporation bank',\n",
      "       'UCO Bank', 'The Ratnakar Bank Ltd', 'Citibank', 'Karur Vysya Bank',\n",
      "       'Punjab National Bank', 'Lakshmi Vilas bank', 'Syndicate Bank',\n",
      "       'Allahabad Bank', 'Bank of Baroda', 'Canara Bank',\n",
      "       'Oriental Bank of Commerce', 'Vijaya Bank', 'State Bank of Hyderabad',\n",
      "       'IDBI Bank', 'State Bank of Patiala', 'Union Bank of India',\n",
      "       'ING Vysya', 'Federal Bank', 'Dena Bank', 'Punjab & Sind bank',\n",
      "       'J&K Bank', 'Deutsche Bank', 'Tamil Nadu Mercantile Bank',\n",
      "       'Indian Bank', 'United Bank of India', 'Abhyuday Co-op Bank Ltd',\n",
      "       'State Bank of Bikaner & Jaipur', 'Saraswat Bank',\n",
      "       'State Bank of Travancore', 'Karnataka Bank', 'South Indian Bank',\n",
      "       'State Bank of Mysore', 'Bank of Rajasthan', 'State Bank of Indore',\n",
      "       'Dhanalakshmi Bank Ltd', 'Catholic Syrian Bank', 'N', 'India Bulls',\n",
      "       'Kerala Gramin Bank', 'Firstrand Bank Limited',\n",
      "       'GIC Housing Finance Ltd', 'B N P Paribas',\n",
      "       'Industrial And Commercial Bank Of China Limited'],\n",
      "      dtype='object')\n",
      "Mobile_Verified\n",
      "Index(['N', 'Y', '0'], dtype='object')\n",
      "Var1\n",
      "Index(['HBXX', 'HBXA', 'HAXM', 'HAXB', 'HBXC', 'HBXD', 'HBXH', 'HAXA', 'HBXB',\n",
      "       'HAYT', 'HCXD', 'HVYS', 'HAVC', 'HCXG', 'HAZD', 'HCYS', 'HCXF', 'HAXC',\n",
      "       'HAXF'],\n",
      "      dtype='object')\n",
      "Filled_Form\n",
      "Index(['N', 'Y', 'Mobile'], dtype='object')\n",
      "Device_Type\n",
      "Index(['Web-browser', 'Mobile', 'G'], dtype='object')\n",
      "Var2\n",
      "Index(['G', 'B', 'C', 'E', 'F', 'D', 'A', 'S122'], dtype='object')\n",
      "Source\n",
      "Index(['S122', 'S143', 'S134', 'S133', 'S159', 'S151', 'S137', 'S127', 'S144',\n",
      "       'S123', 'S156', 'S153', 'S124', 'S161', 'S139', 'S154', 'S157', 'S138',\n",
      "       'S162', 'S141', 'S158', 'S125', 'S129', 'S136', 'S130', 'S155', 'S160',\n",
      "       'S150', 'S135', 'S140', '1'],\n",
      "      dtype='object')\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>DOB</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>23-May-78</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>CYBOSOL</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35000</td>\n",
       "      <td>07-Oct-85</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TATA CONSULTANCY SERVICES LTD (TCS)</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22500</td>\n",
       "      <td>10-Oct-81</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ALCHEMIST HOSPITALS LTD</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>35000</td>\n",
       "      <td>30-Nov-87</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>BIHAR GOVERNMENT</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>100000</td>\n",
       "      <td>17-Feb-84</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>GLOBAL EDGE SOFTWARE</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender  City  Monthly_Income        DOB Lead_Creation_Date  \\\n",
       "0  ID000002C20       0     0           20000  23-May-78          15-May-15   \n",
       "1  ID000004E40       1     1           35000  07-Oct-85          04-May-15   \n",
       "2  ID000007H20       1     2           22500  10-Oct-81          19-May-15   \n",
       "3  ID000008I30       1     3           35000  30-Nov-87          09-May-15   \n",
       "4  ID000009J40       1     4          100000  17-Feb-84          20-May-15   \n",
       "\n",
       "   Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "0             300000.0                  5.0           0.0   \n",
       "1             200000.0                  2.0           0.0   \n",
       "2             600000.0                  4.0           0.0   \n",
       "3            1000000.0                  5.0           0.0   \n",
       "4             500000.0                  2.0       25000.0   \n",
       "\n",
       "                         Employer_Name  Salary_Account  Mobile_Verified Var5  \\\n",
       "0                              CYBOSOL               0                0    0   \n",
       "1  TATA CONSULTANCY SERVICES LTD (TCS)               1                1   13   \n",
       "2              ALCHEMIST HOSPITALS LTD               2                1    0   \n",
       "3                     BIHAR GOVERNMENT               2                1   10   \n",
       "4                 GLOBAL EDGE SOFTWARE               0                1   17   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0                    NaN                    NaN            NaN   \n",
       "1     1               200000.0                    2.0          13.25   \n",
       "2     0               450000.0                    4.0            NaN   \n",
       "3     0               920000.0                    5.0            NaN   \n",
       "4     0               500000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0             NaN                NaN            0            0     0       0   \n",
       "1             NaN             6762.9            0            0     0       0   \n",
       "2             NaN                NaN            0            0     1       1   \n",
       "3             NaN                NaN            0            0     1       1   \n",
       "4             NaN                NaN            0            0     1       2   \n",
       "\n",
       "   Var4  LoggedIn  Disbursed  \n",
       "0     1         0        0.0  \n",
       "1     3         0        0.0  \n",
       "2     1         0        0.0  \n",
       "3     3         0        0.0  \n",
       "4     3         1        0.0  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for feature_name in ['Gender', 'City', 'Salary_Account', 'Mobile_Verified', 'Var1', 'Filled_Form', 'Device_Type', 'Var2', 'Source']:\n",
    "    train[feature_name], uniques  = pd.factorize(train[feature_name])\n",
    "    train[feature_name] = train[feature_name].astype(np.uint16)\n",
    "    print(feature_name)\n",
    "    print(uniques)\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35000</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22500</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>35000</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>100000</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income Lead_Creation_Date  Loan_Amount_Applied  \\\n",
       "0       0     0           20000          15-May-15             300000.0   \n",
       "1       1     1           35000          04-May-15             200000.0   \n",
       "2       1     2           22500          19-May-15             600000.0   \n",
       "3       1     3           35000          09-May-15            1000000.0   \n",
       "4       1     4          100000          20-May-15             500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Salary_Account  Mobile_Verified Var5  \\\n",
       "0                  5.0           0.0               0                0    0   \n",
       "1                  2.0           0.0               1                1   13   \n",
       "2                  4.0           0.0               2                1    0   \n",
       "3                  5.0           0.0               2                1   10   \n",
       "4                  2.0       25000.0               0                1   17   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0                    NaN                    NaN            NaN   \n",
       "1     1               200000.0                    2.0          13.25   \n",
       "2     0               450000.0                    4.0            NaN   \n",
       "3     0               920000.0                    5.0            NaN   \n",
       "4     0               500000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0             NaN                NaN            0            0     0       0   \n",
       "1             NaN             6762.9            0            0     0       0   \n",
       "2             NaN                NaN            0            0     1       1   \n",
       "3             NaN                NaN            0            0     1       1   \n",
       "4             NaN                NaN            0            0     1       2   \n",
       "\n",
       "   Var4  Disbursed  \n",
       "0     1        0.0  \n",
       "1     3        0.0  \n",
       "2     1        0.0  \n",
       "3     3        0.0  \n",
       "4     3        0.0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = train.drop(['ID', 'Employer_Name', 'DOB', 'LoggedIn'], axis=1)\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35000</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22500</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>35000</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>100000</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income Lead_Creation_Date  Loan_Amount_Applied  \\\n",
       "0       0     0           20000          15-May-15             300000.0   \n",
       "1       1     1           35000          04-May-15             200000.0   \n",
       "2       1     2           22500          19-May-15             600000.0   \n",
       "3       1     3           35000          09-May-15            1000000.0   \n",
       "4       1     4          100000          20-May-15             500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Salary_Account  Mobile_Verified Var5  \\\n",
       "0                  5.0           0.0               0                0    0   \n",
       "1                  2.0           0.0               1                1   13   \n",
       "2                  4.0           0.0               2                1    0   \n",
       "3                  5.0           0.0               2                1   10   \n",
       "4                  2.0       25000.0               0                1   17   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0                    0.0                    0.0           0.00   \n",
       "1     1               200000.0                    2.0          13.25   \n",
       "2     0               450000.0                    4.0           0.00   \n",
       "3     0               920000.0                    5.0           0.00   \n",
       "4     0               500000.0                    2.0           0.00   \n",
       "\n",
       "   Processing_Fee EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0             0.0                  0            0            0     0       0   \n",
       "1             0.0             6762.9            0            0     0       0   \n",
       "2             0.0                  0            0            0     1       1   \n",
       "3             0.0                  0            0            0     1       1   \n",
       "4             0.0                  0            0            0     1       2   \n",
       "\n",
       "   Var4  Disbursed  \n",
       "0     1        0.0  \n",
       "1     3        0.0  \n",
       "2     1        0.0  \n",
       "3     3        0.0  \n",
       "4     3        0.0  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#NaN的处理\n",
    "#19.EMI_Loan_Submitted -提交的EMI贷款金额（INR）\n",
    "train[[\"EMI_Loan_Submitted\"]] = train[[\"EMI_Loan_Submitted\"]].fillna(0)\n",
    "#18.Processing_Fee - 提交贷款的处理费（INR）\n",
    "train[[\"Processing_Fee\"]] = train[[\"Processing_Fee\"]].fillna(0)\n",
    "#17.Interest_Rate - 提交贷款金额的利率\n",
    "train[[\"Interest_Rate\"]] = train[[\"Interest_Rate\"]].fillna(0)\n",
    "#16.Loan_Tenure_Submitted - 提交的贷款期限（单位为年，在看到资格后修改和选择）\n",
    "train[[\"Loan_Tenure_Submitted\"]] = train[[\"Loan_Tenure_Submitted\"]].fillna(0)\n",
    "#7.Loan_Amount_Applied - 贷款申请请求金额（印度卢比，INR）\n",
    "train[[\"Loan_Amount_Applied\"]] = train[[\"Loan_Amount_Applied\"]].fillna(0)\n",
    "#8.Loan_Tenure_Applied - 贷款申请期限（单位为年） \n",
    "train[[\"Loan_Tenure_Applied\"]] = train[[\"Loan_Tenure_Applied\"]].fillna(0)\n",
    "#Existing_EMI -现有贷款的EMI（EMI：电子货币机构许可证）\n",
    "train[[\"Existing_EMI\"]] = train[[\"Existing_EMI\"]].fillna(0)\n",
    "#15.Loan_Amount_Submitted - 提交的贷款金额（在看到资格后修改和选择）\n",
    "train[[\"Loan_Amount_Submitted\"]] = train[[\"Loan_Amount_Submitted\"]].fillna(0)\n",
    "\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Disbursed\n"
     ]
    }
   ],
   "source": [
    "for a in train.columns:\n",
    "    if np.any(train[a].isnull()) == True:\n",
    "        print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#删除所有存在nan的行\n",
    "train = train.dropna(axis=0,how='any')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "train[['Var5', 'EMI_Loan_Submitted']] = train[['Var5', 'EMI_Loan_Submitted']].astype(np.float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 87019 entries, 0 to 87019\n",
      "Data columns (total 22 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   Gender                 87019 non-null  uint16 \n",
      " 1   City                   87019 non-null  uint16 \n",
      " 2   Monthly_Income         87019 non-null  int64  \n",
      " 3   Lead_Creation_Date     87019 non-null  object \n",
      " 4   Loan_Amount_Applied    87019 non-null  float64\n",
      " 5   Loan_Tenure_Applied    87019 non-null  float64\n",
      " 6   Existing_EMI           87019 non-null  float64\n",
      " 7   Salary_Account         87019 non-null  uint16 \n",
      " 8   Mobile_Verified        87019 non-null  uint16 \n",
      " 9   Var5                   87019 non-null  float64\n",
      " 10  Var1                   87019 non-null  uint16 \n",
      " 11  Loan_Amount_Submitted  87019 non-null  float64\n",
      " 12  Loan_Tenure_Submitted  87019 non-null  float64\n",
      " 13  Interest_Rate          87019 non-null  float64\n",
      " 14  Processing_Fee         87019 non-null  float64\n",
      " 15  EMI_Loan_Submitted     87019 non-null  float64\n",
      " 16  Filled_Form            87019 non-null  uint16 \n",
      " 17  Device_Type            87019 non-null  uint16 \n",
      " 18  Var2                   87019 non-null  uint16 \n",
      " 19  Source                 87019 non-null  uint16 \n",
      " 20  Var4                   87019 non-null  int64  \n",
      " 21  Disbursed              87019 non-null  float64\n",
      "dtypes: float64(10), int64(2), object(1), uint16(9)\n",
      "memory usage: 10.8+ MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35000</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22500</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>35000</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>100000</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>17.0</td>\n",
       "      <td>0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income Lead_Creation_Date  Loan_Amount_Applied  \\\n",
       "0       0     0           20000          15-May-15             300000.0   \n",
       "1       1     1           35000          04-May-15             200000.0   \n",
       "2       1     2           22500          19-May-15             600000.0   \n",
       "3       1     3           35000          09-May-15            1000000.0   \n",
       "4       1     4          100000          20-May-15             500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Salary_Account  Mobile_Verified  Var5  \\\n",
       "0                  5.0           0.0               0                0   0.0   \n",
       "1                  2.0           0.0               1                1  13.0   \n",
       "2                  4.0           0.0               2                1   0.0   \n",
       "3                  5.0           0.0               2                1  10.0   \n",
       "4                  2.0       25000.0               0                1  17.0   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0                    0.0                    0.0           0.00   \n",
       "1     1               200000.0                    2.0          13.25   \n",
       "2     0               450000.0                    4.0           0.00   \n",
       "3     0               920000.0                    5.0           0.00   \n",
       "4     0               500000.0                    2.0           0.00   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0             0.0                 0.0            0            0     0       0   \n",
       "1             0.0              6762.9            0            0     0       0   \n",
       "2             0.0                 0.0            0            0     1       1   \n",
       "3             0.0                 0.0            0            0     1       1   \n",
       "4             0.0                 0.0            0            0     1       2   \n",
       "\n",
       "   Var4  Disbursed  \n",
       "0     1        0.0  \n",
       "1     3        0.0  \n",
       "2     1        0.0  \n",
       "3     3        0.0  \n",
       "4     3        0.0  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>Lead_Creation_Date_Month</th>\n",
       "      <th>Lead_Creation_Date_Season</th>\n",
       "      <th>Lead_Creation_Date_Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35000</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22500</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>35000</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>100000</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>17.0</td>\n",
       "      <td>0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "0       0     0           20000             300000.0                  5.0   \n",
       "1       1     1           35000             200000.0                  2.0   \n",
       "2       1     2           22500             600000.0                  4.0   \n",
       "3       1     3           35000            1000000.0                  5.0   \n",
       "4       1     4          100000             500000.0                  2.0   \n",
       "\n",
       "   Existing_EMI  Salary_Account  Mobile_Verified  Var5  Var1  \\\n",
       "0           0.0               0                0   0.0     0   \n",
       "1           0.0               1                1  13.0     1   \n",
       "2           0.0               2                1   0.0     0   \n",
       "3           0.0               2                1  10.0     0   \n",
       "4       25000.0               0                1  17.0     0   \n",
       "\n",
       "   Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0                    0.0                    0.0           0.00   \n",
       "1               200000.0                    2.0          13.25   \n",
       "2               450000.0                    4.0           0.00   \n",
       "3               920000.0                    5.0           0.00   \n",
       "4               500000.0                    2.0           0.00   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0             0.0                 0.0            0            0     0       0   \n",
       "1             0.0              6762.9            0            0     0       0   \n",
       "2             0.0                 0.0            0            0     1       1   \n",
       "3             0.0                 0.0            0            0     1       1   \n",
       "4             0.0                 0.0            0            0     1       2   \n",
       "\n",
       "   Var4  Disbursed  Lead_Creation_Date_Month  Lead_Creation_Date_Season  \\\n",
       "0     1        0.0                         4                          1   \n",
       "1     3        0.0                         4                          1   \n",
       "2     1        0.0                         4                          1   \n",
       "3     3        0.0                         4                          1   \n",
       "4     3        0.0                         4                          1   \n",
       "\n",
       "   Lead_Creation_Date_Year  \n",
       "0                       15  \n",
       "1                       15  \n",
       "2                       15  \n",
       "3                       15  \n",
       "4                       15  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#新增特征列  Lead_Creation_Date转化成月份 年份 季度 然后干掉Lead_Creation_Date列\n",
    "train['Lead_Creation_Date_Month'] = 0\n",
    "train['Lead_Creation_Date_Season'] = 0\n",
    "train['Lead_Creation_Date_Year'] = 0\n",
    "\n",
    "def handle_Lead_Creation_Date_month(x):\n",
    "    month_dict = {\n",
    "        'Jan':0,\n",
    "        'Feb':1,\n",
    "        'Mar':2,\n",
    "        'Apr':3,\n",
    "        'May':4,\n",
    "        'Jun':5,\n",
    "        'Jul':6,\n",
    "        'Aug':7,\n",
    "        'Sep':8,\n",
    "        'Oct':9,\n",
    "        'Nov':10,\n",
    "        'Dec':11,\n",
    "    }\n",
    "    date_data = x.split('-')\n",
    "    return month_dict[date_data[1]]\n",
    "\n",
    "def handle_Lead_Creation_Date_season(x):\n",
    "    month_dict = {\n",
    "        'Jan':0,\n",
    "        'Feb':0,\n",
    "        'Mar':0,\n",
    "        'Apr':1,\n",
    "        'May':1,\n",
    "        'Jun':1,\n",
    "        'Jul':2,\n",
    "        'Aug':2,\n",
    "        'Sep':2,\n",
    "        'Oct':3,\n",
    "        'Nov':3,\n",
    "        'Dec':3,\n",
    "    }\n",
    "    date_data = x.split('-')\n",
    "    return month_dict[date_data[1]]\n",
    "\n",
    "def handle_Lead_Creation_Date_year(x):\n",
    "    date_data = x.split('-')\n",
    "    return int(date_data[2])\n",
    "\n",
    "train['Lead_Creation_Date_Month'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_month(x), 0).astype(np.int64)\n",
    "train['Lead_Creation_Date_Season'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_season(x), 0).astype(np.int64)\n",
    "train['Lead_Creation_Date_Year'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_year(x), 0).astype(np.int64)\n",
    "\n",
    "\n",
    "train = train.drop(['Lead_Creation_Date'], axis=1)\n",
    "\n",
    "train.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 87019 entries, 0 to 87019\n",
      "Data columns (total 24 columns):\n",
      " #   Column                     Non-Null Count  Dtype  \n",
      "---  ------                     --------------  -----  \n",
      " 0   Gender                     87019 non-null  uint16 \n",
      " 1   City                       87019 non-null  uint16 \n",
      " 2   Monthly_Income             87019 non-null  int64  \n",
      " 3   Loan_Amount_Applied        87019 non-null  float64\n",
      " 4   Loan_Tenure_Applied        87019 non-null  float64\n",
      " 5   Existing_EMI               87019 non-null  float64\n",
      " 6   Salary_Account             87019 non-null  uint16 \n",
      " 7   Mobile_Verified            87019 non-null  uint16 \n",
      " 8   Var5                       87019 non-null  float64\n",
      " 9   Var1                       87019 non-null  uint16 \n",
      " 10  Loan_Amount_Submitted      87019 non-null  float64\n",
      " 11  Loan_Tenure_Submitted      87019 non-null  float64\n",
      " 12  Interest_Rate              87019 non-null  float64\n",
      " 13  Processing_Fee             87019 non-null  float64\n",
      " 14  EMI_Loan_Submitted         87019 non-null  float64\n",
      " 15  Filled_Form                87019 non-null  uint16 \n",
      " 16  Device_Type                87019 non-null  uint16 \n",
      " 17  Var2                       87019 non-null  uint16 \n",
      " 18  Source                     87019 non-null  uint16 \n",
      " 19  Var4                       87019 non-null  int64  \n",
      " 20  Disbursed                  87019 non-null  float64\n",
      " 21  Lead_Creation_Date_Month   87019 non-null  int64  \n",
      " 22  Lead_Creation_Date_Season  87019 non-null  int64  \n",
      " 23  Lead_Creation_Date_Year    87019 non-null  int64  \n",
      "dtypes: float64(10), int64(5), uint16(9)\n",
      "memory usage: 12.1 MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "train.to_csv(dpath +'Bank_FE_train_org.csv',index=False,header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
